package com.dyz.swordFingerOffer;

import java.util.ArrayList;
import java.util.Collections;

public class GetMedian41 {
    private ArrayList<Integer> list = new ArrayList<>();

    public void Insert(Integer num) {
        list.add(num);
        //可以自己写排序
        Collections.sort(list);
    }

    public Double GetMedian() {
        int mid = list.size() >>1;
        if(list.size()%2==0){
            return (list.get(mid) + list.get(mid-1)) / 2.0;
        }else{
            return (double) list.get(mid);
        }

    }
}
